<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Permission_Model extends CI_Model
{
  function __construct() {
	  parent::__construct();
  }
  function get_all_permission(){
	  return $this->db->get('sys_permission')->result();
  }
  
  function get_permission_by_id(){
	  $ID = $this->uri->segment(3);
	  $this->db->where('permission_id',$ID);
	  return $this->db->get('sys_permission')->row();
  }
  
  function save(){
	  $permission_id = (int)$this->uri->segment(3);
	  $data = array(
		'permission_name' => $this->input->post('permission_name'),
		'permission_notice' => $this->input->post('permission_notice')
	  );
	  
	  if($permission_id!=0){
		  $this->db->where('permission_id',$permission_id);
		  if($this->db->update('sys_permission',$data)){
			  return true;
		  }else{
			  return false;
		  }
	  }else{
		  if($this->db->insert('sys_permission',$data)){
			  return true;
		  }else{
			  return false;
		  }
	  }
  }
}
?>
